package cn.com.freelibra.forum.service.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.com.freelibra.forum.dao.UserMapper;
import cn.com.freelibra.forum.po.User;
import cn.com.freelibra.forum.po.UserExample;
import cn.com.freelibra.forum.service.UserService;

@Service("userService")  
public class UserServiceImpl implements UserService{
    @Resource  
    private UserMapper dao;
    
	@Override
	public User load(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> byName(String user_name) {
		// TODO Auto-generated method stub
		UserExample userExample = new UserExample();
		userExample.createCriteria().andUserNameEqualTo(user_name);
		return dao.selectByEntity(userExample);
	}

	@Override
	public HashMap<String, Object> findbyallresulte(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int registerUser(User user) {
		// TODO Auto-generated method stub
		return dao.insertSelective(user);
	}

	@Override
	public void updateUser(User user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public User byOpenId(String open_id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> byEmail(String email) {
		UserExample userExample = new UserExample();
		userExample.createCriteria().andEmailEqualTo(email);
		return dao.selectByEntity(userExample);
	}

	@Override
	public User byNameAndPassword(String userName, String password) {
		UserExample userExample = new UserExample();
		userExample.createCriteria().andUserNameEqualTo(userName);
		List<User> users = dao.selectByEntity(userExample);
		if(users!=null&&users.size()>0){//登陆用户存在
			return users.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Set<String> getRoles(String username) {
		Set<String> tt=new HashSet<>();
		tt.add("sss");
		return tt;
	}

	@Override
	public Set<String> getPermissions(String username) {
		Set<String> tt=new HashSet<>();
		tt.add("sss");
		return tt;
	}

}
